class Solution {
public:
    vector<vector<int>> rst;
    vector<int> temp;
    vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
        sort(candidates.begin(), candidates.end());

        combinationSum2Step(candidates, 0, target);

        return rst;
    }

    void combinationSum2Step(vector<int>& candidates, int start, int target) {
        if(target < 0) {
            return;
        }

        if(target == 0) {
            rst.push_back(temp);
            return;
        }

        for(int i = start; i < candidates.size(); ++i) {
            if(i != start && candidates[i] == candidates[i-1]){
                continue;
            }

            temp.push_back(candidates[i]);
            combinationSum2Step(candidates, i + 1, target - candidates[i]);
            temp.pop_back();
        }
    }
};